#include "player.h"
#include "qfile.h"

Player::Player() : audioOutput(Phonon::MusicCategory)
{
	this->currentSong = NULL;

   Phonon::createPath(this, &audioOutput);
}

Song *Player::getCurrentSong()
{
	return this->currentSong;
}

void Player::setSong(Song *song)
{
	if(song == NULL)
		return;
	QString songPath = song->getFilename();
	QFile file(songPath);
	if(file.exists()){
		this->currentSong = song;
		this->setCurrentSource(Phonon::MediaSource(songPath));
		this->play();
	} else {
		//lanzar exception
	}
}

void Player::setVolumeControl(Phonon::VolumeSlider *volumeSlider)
{
	volumeSlider->setAudioOutput(&audioOutput);
}

bool Player::hasSong()
{
	return (this->currentSong != NULL);
}

